package com.jic.market.facade;

import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.product.after.api.ProductListApi;
import com.jic.product.after.request.GoodsPageQueryRequest;
import com.jic.product.after.response.GoodsPageQueryResponse;
import com.jic.product.after.response.GoodsQueryInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * description: ProductApiFacade
 * date: 2020/4/27 18:58
 * author: wangys
 * version: 1.0
 */
@Component
public class ProductApiFacade {
    @Autowired
    ProductListApi productListApi;


    public GoodsPageQueryResponse queryMarketById(Long productId){
        RestResult<GoodsPageQueryResponse> goodsPageQueryResponseRestResult = productListApi.queryMarketById(productId);
        GoodsPageQueryResponse data = goodsPageQueryResponseRestResult.getData();
        return data;
    }

    public GoodsQueryInfo getGoodsInfo(Long productId){
        RestResult<GoodsPageQueryResponse> goodsPageQueryResponseRestResult = productListApi.queryMarketById(productId);
        GoodsPageQueryResponse data = goodsPageQueryResponseRestResult.getData();
        return data.getGoodsInfo();
    }

    public List<GoodsPageQueryResponse> queryByAllCondition(GoodsPageQueryRequest request){
        RestResult<PageResult<GoodsPageQueryResponse>> pageResultRestResult = productListApi.queryByAllCondition(request);
        List<GoodsPageQueryResponse> rows = pageResultRestResult.getData().getRows();
        return rows;
    }
}
